Ext.define('Admin.view.overtimeapprove.OvertimeApproveViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.overtimeApproveViewController',

    overtimeTaskClime:function(view,recIndex,cellIndex,item,e,record){
        Ext.Ajax.request({
            url:'overtime/overtimeClime',
            method:'post',
            defaultHeaders: {
                "X-CSRF-TOKEN": document.getElementsByTagName('meta')['_csrf'].content
            },
            params:{
                taskId:record.get('taskId')
            },
            success:function(response,option){
                var json = Ext.util.JSON.decode(response.responseText);
                if (json.success) {
                    Ext.Msg.alert("操作成功",json.msg);
                    Ext.getCmp('overtimeApproveGrid').getStore().reload();
                } else {
                    Ext.Msg.alert("操作失败",json.msg);
                }
            }
        })
    },

    openOvertimeApproveFormWindow:function(view,recIndex,cellIndex,item,e,record){
        if (record.get('taskDefinitionKey')=="reApply") {
            var win = Ext.create('widget.overtimeApproveViewWindow',{
                title:'调整申请',
                items:{xtype:'overtimeReapplyForm'}
            });
            var form = win.down('form').getForm().loadRecord(record);
            var begin = Ext.getCmp('begin');
            Ext.getCmp('end').setMinValue(begin.value);
        }else{
            var win = Ext.create('widget.overtimeApproveViewWindow',{
                items:{xtype:'overtimeApproveFrom'}
            });

            //根据不同流程节点设置窗口属性
            if (record.get('taskDefinitionKey')=="depManagerApprove") {
                win.setTitle('部门经理审批');
            } else if(record.get('taskDefinitionKey')=="hrApprove"){
                win.setTitle('人事部审批');
            }else if (record.get('taskDefinitionKey')=="hrFile") {
                win.setTitle('人事部归档');
            }

            var overtimeApproveFrom = Ext.getCmp('overtimeApproveFrom').getForm();
            overtimeApproveFrom.findField('taskId').setValue(record.get('taskId'));
            overtimeApproveFrom.findField('id').setValue(record.get('id'));
            overtimeApproveFrom.findField('taskDefinitionKey').setValue(record.get('taskDefinitionKey'));
            overtimeApproveFrom.findField('processInstanceId').setValue(record.get('processInstanceId'));
        }
        
        

    },

    closeWindow:function(bt){
        var win  = bt.up('window');
        if(win){
            win.close();
        }
    },

    onClickOvertimeApproveFormSubmit:function(bt) {
        var form = bt.up('form').getForm();
        var pass = null;
        if (form.findField('taskDefinitionKey').getValue()=="depManagerApprove") {
            pass = 'depManagerPass';
        }else if (form.findField('taskDefinitionKey').getValue()=="hrApprove") {
            pass = 'hrPass';
        }

        var aKeys = [pass];
        var aValues = [form.findField('isPass').getGroupValue()];
        var aTypes = ['B'];
        form.submit({
            url:'overtime/overtimeComplete',
            method:'post',
            params:{
                keys:aKeys,
                values:aValues,
                types:aTypes,
                "_csrf": document.getElementsByTagName('meta')['_csrf'].content
            },
            success:function(form,actions){
                Ext.Msg.alert("操作成功",actions.result.msg);
                bt.up('window').close();
                Ext.getCmp('overtimeApproveGrid').getStore().reload();
                if (Ext.getCmp('overtimeFileGrid')!=null) {
                    Ext.getCmp('overtimeFileGrid').getStore().reload();
                }
            },
            failure:function(form,actions){
                Ext.Msg.alert("操作失败",actions.result.msg);
            }  
        })
    }
})